import { Col, Icon, Tooltip } from 'antd';
import * as React from 'react';
import { NavLink } from 'react-router-dom';

export interface OperatorItemType {
  type: 'link' | 'icon';
  icon: string;
  key: string;
  title: string;
  style?: object;
  onClick?: (e:any) => any;
  link?: string | undefined;
}

export default function OperatorItem({
  setting,
  length
}: {
  setting: OperatorItemType;
  length: number;
}) {
  if (length === 0) {
    return null;
  }
  const { type, icon, key, style, link, title, onClick } = setting;
  return (
    <Col
      span={24 / Math.min(length, 4)}
      style={{ textAlign: 'center', ...style }}
      key={key}
    >
      {type === 'link' && (
        <NavLink to={link || ''}>
          <Tooltip title={title}>
            <Icon type={icon} />
          </Tooltip>
        </NavLink>
      )}
      {type === 'icon' && (
        <Tooltip title={title}>
          <Icon type={icon} onClick={onClick}/>
        </Tooltip>
      )}
    </Col>
  );
}
